package com.t235.gc.user.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
public class RegService {

    @Autowired
    private SmsService smsService;

    public Integer sendPhoneCode(String phone){
        //生成验证码
        Integer code = new Random().nextInt(10000);
        smsService.sendMessage(phone,code.toString());
        return 1;
    }

    public static void main(String[] args) {
        SmsService smsService = new SmsService();
        Integer code = new Random().nextInt(10000);
        smsService.sendMessage("15173070607",code.toString());
    }


    public boolean validatephone(String phone, String code) throws Exception{
        String dbcode = smsService.getCode(phone);
        if(dbcode == null){
            throw new Exception("激活号码不存在!");
        }
        if(!dbcode.equals(code)){
            throw new Exception("验证码输入错误!");
        }
        return true;
    }
}
